two-pointer solution

visit shbcf.ru